var app = getApp();
var c = require('../common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classon: 1,
    _fix: 0,
    taokeinfo: null,
    taokereclass: null,
    overflow: 'hidden',
    height: '100rpx',
    shoufang: 1,
    overflowc: 'hidden',
    heightc: '100rpx',
    shoufangc: 1,
    taokelist: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var dgoods_id = options.dgoods_id;//父id
    var goods_id  = options.goods_id;
    console.log(goods_id);
    // var goods_id= 641;
    // var dgoods_id = 644;//大纲用的
    this.setData({
      goods_id: dgoods_id
    })
    var user_id = wx.getStorageSync('userInfo').user_id;
    var sqlinfo = 'w(goods_id=' + goods_id + ')l(1)';


    c.ajax(
      app.url + 'addHistory',
      { uid: user_id, goods_id: goods_id, typeinfo: 1 },
      res => {
        console.log(res);
      }
    )


    //套课信息
    c.ajax(
      app.dbs + 'goods',
      { sql: sqlinfo },
      res => {
        this.setData({
          taokeinfo: res.data,
        })

      }
    )

    //套课列表(大纲)
    c.ajax(
      app.url + 'daganggoods',
      { goods_id: dgoods_id, nowGoods_id: goods_id },
      res => {
        this.setData({
          taokelist: res.data
        })
        console.log(res.data);
      }
    )
    //评论
    c.ajax(
      app.url + 'comment',
      { goods_id: dgoods_id, user_id: user_id },
      res => {
        this.setData({
          taokerecommen: res.data,
          pfstarnum: res.data.pfstarnum,
          pfstarnum_not: res.data.pfstarnum_not,
          list: res.data.data,
          status: res.data.status,
          subscribe: res.data.subscribe,
        })

      }
    )

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var query = wx.createSelectorQuery().in(this)
    var that = this;
    query.select('#topinfo').boundingClientRect(function (res) {
      that.setData({ topmenu: res.top })       // 这个组件内 #topinfo 节点的上边界坐标
    }).exec()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  ckickon: function (e) {
    var id = e.currentTarget.dataset.id;
    this.setData({ classon: id });
  },
  onPageScroll: function (scroll, that) {
    var topmenu = this.data.topmenu;
    if (scroll.scrollTop > topmenu) {
      this.setData({ _fix: 1 });
    } else {
      this.setData({ _fix: 0 });
    }
  },
  zanoperation: function () {
    this.setData({
      shoufang: 2,
      overflow: '',
      height: 'auto',
    })
  },
  shouoperation: function () {
    this.setData({
      shoufang: 1,
      overflow: 'hidden',
      height: '100rpx',
    })
  },
  zanoperationc: function () {
    this.setData({
      shoufangc: 2,
      overflowc: '',
      heightc: 'auto',
    })
  },
  shouoperationc: function () {
    this.setData({
      shoufangc: 1,
      overflowc: 'hidden',
      heightc: '100rpx',
    })
  },
  clicksub: function (e) {
    var goods_id = e.currentTarget.dataset.goods_id;

    var user_id = wx.getStorageSync('userInfo').user_id;
    c.ajax(
      app.url + 'addSubscript',
      { goods_id: goods_id, user_id: user_id },
      res => {
        this.setData({
          subscribe: res.data,
        })

      }
    )
  }
})